/*
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2004-2006 Intel Corporation. All Rights Reserved.
//
//     Intel Integrated Performance Primitives AAC Encode Sample for Windows*
//
//  By downloading and installing this sample, you hereby agree that the
//  accompanying Materials are being provided to you under the terms and
//  conditions of the End User License Agreement for the Intel Integrated
//  Performance Primitives product previously accepted by you. Please refer
//  to the file ippEULA.rtf or ippEULA.txt located in the root directory of your Intel IPP
//  product installation for more information.
//
//  MPEG-4 and AAC are international standards promoted by ISO, IEC, ITU, ETSI
//  and other organizations. Implementations of these standards, or the standard
//  enabled platforms may require licenses from various entities, including
//  Intel Corporation.
//
*/

#ifndef __PSYCHOACOUSTIC_H
#define __PSYCHOACOUSTIC_H

#include "ipps.h"
#include "ippac.h"
#include "aaccmn_const.h"
#include "aac_enc_int.h"
#include "align.h"

#define MAX_PPT_SHORT 48
#define MAX_PPT_LONG  72
#define NUM_UNPRED_LINES_LONG 6

typedef struct {
  Ipp32s bu;
  Ipp32s bo;
  Ipp32s w1;
  Ipp32s w2;
} AACp2sb;

typedef struct
{
  Ipp32s            sampling_frequency;
  Ipp32s            num_ptt;
  Ipp32s*           w_low;
  Ipp16s*           w_width;
  Ipp16s*           bval;
  Ipp16s*           qsthr;

} sPsyPartitionTable;

typedef struct
{
  __ALIGN Ipp16s    r [2][3][__ALIGNED(1024)];
  __ALIGN Ipp16s    re[2][3][__ALIGNED(1024)];
  __ALIGN Ipp16s    im[2][3][__ALIGNED(1024)];

  __ALIGN Ipp16s    r_short [2][3][8][__ALIGNED(128)];
  __ALIGN Ipp16s    re_short[2][3][8][__ALIGNED(128)];
  __ALIGN Ipp16s    im_short[2][3][8][__ALIGNED(128)];

  __ALIGN Ipp32s    smr_long [2][__ALIGNED(MAX_SFB)];
  __ALIGN Ipp32s    smr_short[2][__ALIGNED(MAX_SFB)];

  __ALIGN Ipp32s    nb_long [2][2][__ALIGNED(MAX_PPT_LONG)];

  Ipp32s            rScaleFactor[2][3];
  Ipp32s            rScaleFactorShort[2][3][8];
  Ipp32s            nb_longScaleFactor[2];

  Ipp32s            block_type;
  Ipp32s            desired_block_type;
  Ipp32s            next_desired_block_type[2];
  Ipp32s            stereo_mode[2];

  Ipp32s            ms_coef[2];

  Ipp32s            next_frame_PE;
  Ipp32s            curr_frame_PE;

} sPsychoacousticBlock;

typedef struct
{
  __ALIGN Ipp16s      sprdngf_long[MAX_PPT_LONG * MAX_PPT_LONG];
  __ALIGN Ipp16s      sprdngf_short[MAX_PPT_SHORT * MAX_PPT_SHORT];

  __ALIGN Ipp32s      sfb_width_long[MAX_SFB];
  __ALIGN Ipp32s      sfb_width_short[MAX_SFB];

  __ALIGN Ipp32s      w_width_long_inv[MAX_PPT_LONG];
  __ALIGN Ipp32s      w_width_short_inv[MAX_PPT_SHORT];

  Ipp16s*             input_data[2][2];

  Ipp32s              iblen_long;
  Ipp32s              iblen_short;

  Ipp32s              current_f_r_index;
  Ipp32s              prev_f_r_index;
  Ipp32s              prev_prev_f_r_index;

  Ipp32s              nb_curr_index;
  Ipp32s              nb_prev_index;

  Ipp32s*             sfb_offset_long;
  Ipp32s*             sfb_offset_short;
  Ipp32s              num_sfb_long;
  Ipp32s              num_sfb_short;

  Ipp32s              sfb_width_longScale;
  Ipp32s              sfb_width_shortScale;
  Ipp32s              longScale;
  Ipp32s              shortScale;

  Ipp32s              sampling_frequency_index;
  Ipp32s              ns_mode;

  sPsyPartitionTable* longWindow;
  sPsyPartitionTable* shortWindow;
  AACp2sb*            aacenc_p2sb_l;
  AACp2sb*            aacenc_p2sb_s;

  IppsFFTSpec_R_16s*  pFFTSpecShort;
  IppsFFTSpec_R_16s*  pFFTSpecLong;
  Ipp8u*              pBuffer;
} sPsychoacousticBlockCom;

extern sPsyPartitionTable aacienc_psy_partition_tables_long[];
extern sPsyPartitionTable aacienc_psy_partition_tables_short[];
extern Ipp16s AACI_HANN_long[];
extern Ipp16s AACI_HANN_short[];
extern AACp2sb *aacienc_p2sb_l[];
extern AACp2sb *aacienc_p2sb_s[];

#ifdef  __cplusplus
extern "C" {
#endif

  AACStatus aaciencInitPsychoacousticCom(sPsychoacousticBlockCom* pBlock,
                                         Ipp8u* mem,
                                         Ipp32s sf_index,
                                         Ipp32s ns_mode,
                                         Ipp32s *size_all);
  void aaciencInitPsychoacoustic(sPsychoacousticBlock* pBlock);
  void aaciencFreePsychoacousticCom(sPsychoacousticBlockCom* pBlock);

  void aaciencPsychoacoustic(sPsychoacousticBlock** pBlock,
                             sPsychoacousticBlockCom* pBlockCom,
                             Ipp32s ms_thr,
                             Ipp32s numCh);

#ifdef  __cplusplus
}
#endif
#endif//__PSYCHOACOUSTIC_H
